<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>业主认证</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<input type="hidden" id="reanNames" th:value="${session.USER_SESSION.realname}"></input>
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">

            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input servCustName" placeholder="业主" />
                </div>

                <div class="layui-input-inline">
                    <input type="text" class="layui-input servTitle" placeholder="小区" />
                </div>

                <a class="layui-btn search_btn" data-type="reload" id="serchBtn">搜索</a>
            </div>
        </form>

    </blockquote>
    <table id="serviceList" lay-filter="serviceList"></table>
    <input type="hidden" id="servDueTo" name="servDueTo" style="border: none;margin: 10px" th:value="${session.USER_SESSION.realname}" readonly></input>
    <!--操作-->
    <script type="text/html" id="usersListBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="pass">通过</a>
        <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="reject">驳回</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        var reanNames=$("#reanNames").val();

        //服务单列表
        laydate.render({
            elem: '#startTime',//指定元素
        });
        laydate.render({
            elem: '#endTime',//指定元素
        });
        var tableIns = table.render({
            elem: '#serviceList',
            url : 'getAllAttestation',
            page : true,
            height : "full-125",
            limit : 20,
            limits : [10,15,20,25],
            id : "serviceListTable",
            cols : [[
                {type: "checkbox", fixed:"left"},
                {field: 'id', title: '编号',align:"center"},
                {field: 'name', title: '账户昵称',align:"center"},
                {field: 'home', title: '业主姓名', align:"center",templet:function (row) {
                        return row.home.homeName;
                    }},
                {field: 'home', title: '小区', align:"center",templet:function (row) {
                        return row.home.areaName;
                    }},
                {field: 'home', title: '单元', align:"center",templet:function (row) {
                        return row.home.unitId;
                    }},
                {field: 'home', title: '房号', align:"center",templet:function (row) {
                        return row.home.hoseNumber;
                    }},
                {field: 'home', title: '电话', align:"center",templet:function (row) {
                        return row.home.telephone;
                    }},
                {title: '操作', width:250, templet:'#usersListBar',fixed:"right",align:"center"}
            ]]
        });
        $(".search_btn").on("click",function(){
            table.reload("serviceListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    'home.homeName' : $(".servCustName").val(),//搜索的关键字
                    community: $(".servTitle").val(),  //搜索的关键字

                }
            })
        });

        table.on("tool(serviceList)",function (obj) {
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'pass':
                    pass(data);
                    break;
                case 'reject':
                    reject(data);
                    break;

            }
        });

        setTimeout(function() {
            if(document.all) {
                document.getElementById("serchBtn").click();
            }
            else {
                var e = document.createEvent("MouseEvents");
                e.initEvent("click", true, true);
                document.getElementById("serchBtn").dispatchEvent(e);
            }
        }, 10);


        //弹出提示框
        function pass(data){
            console.log(data);
            var did = data.id;
            var st = "请确认，通过"+data.home.areaName+"的业主："+data.home.homeName+"，的认证？"
            layer.confirm(st, {icon: 3, title: '提示信息'}, function () {
                console.log("最终传值",did);
                $.ajax({
                    type:"POST",
                    url:"passAttestation",
                    data:{uId:did},
                    success:function (res) {
                        if(res.code=1002){
                            layer.msg("已通过");
                            document.getElementById("serchBtn").click();
                        }else if(res.code= -1002){
                            layer.msg("请求失败，请刷新尝试");
                        }
                    },
                    field:function () {
                        layer.msg("网络异常，请稍后尝试");
                    }

                });
            });
        }
        function reject(data){
            console.log(data);
            var did = data.id;
            var st = "请确认，驳回"+data.home.areaName+"的业主："+data.home.homeName+"，的认证？"
            layer.confirm(st, {icon: 3, title: '提示信息'}, function () {
                console.log("最终传值",did);
                $.ajax({
                    type:"POST",
                    url:"rejectAttestation",
                    data:{uId:did},
                    success:function (res) {
                        if(res.code=200){

                            layer.msg("已驳回");
                            document.getElementById("serchBtn").click();

                        }else if(res.code=401){
                            layer.msg("驳回失败，请刷新后尝试");
                        }
                    },
                    field:function () {
                        layer.msg("网络异常，请稍后尝试");
                    }

                });
            });
        }

    })

</script>
</body>

</html>